<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="尺寸名称">
              <a-input placeholder="请输入尺寸名称" v-model="queryParam.queryName"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="创建时间">
              <j-date placeholder="请选择创建时间" v-model="queryParam.queryTime"></j-date>
            </a-form-item>
          </a-col>

          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" style="color: #F9D532;width: 80px;height: 36px;background: #333333;border-style: none;">查询</a-button>
              <a-button type="primary" @click="searchReset" style="margin-left: 8px;width: 80px;height: 36px;background: #eae7e7;border-style: none;color: #323232">重置</a-button>
            </span>
          </a-col>

          <div style="float: right;margin-right: 10px;">
            <a-button type="primary" @click="add_category(0)" icon="plus" style="color: #F9D532;width: 110px;height: 36px;background: #333333;border-style: none;float: left;margin-right: 5px;" >新增</a-button>
            <a-upload style="margin-left: 8px;float: left;margin-right: 5px" name="file" :showUploadList="false"
                      :multiple="false"
                      :customRequest="importExcel"
                      :action="importExcelUrl" @change="handleImportExcel">
              <a-button type="primary" style="color: #F9D532;width: 85px;height: 34px;background: #333333;border-style: none;margin-right: 5px" :loading="confirmLoading">导入</a-button>
            </a-upload>
            <a-button type="primary" @click="exportExcel" style="color: #F9D532;width: 85px;height: 34px;background: #333333;border-style: none;float: left;margin-right: 5px">导出</a-button>
          </div>

        </a-row>
      </a-form>
    </div>

    <div style="background: #f2f2f2;height: 10px;width: auto;margin-top: 10px;margin-bottom: 30px;"></div>

    <div>
      <div style="border: none;background-color: #ffffff;padding-bottom: 28px;">
        <span style="font-size: 16px;float: left;color:#000000;font-weight: bold">净体尺寸列表</span>
<!--        <a-button type="primary" @click="exportExcel" style="color: #F9D532;width: 85px;height: 34px;background: #333333;border-style: none;float: right;margin-right: 5px">导入</a-button>-->
<!--        <a-button type="primary" @click="exportExcel" style="color: #F9D532;width: 85px;height: 34px;background: #333333;border-style: none;float: right;margin-right: 5px">导出</a-button>-->

      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange" style="margin-top: 10px;">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <div align="center" style="align-content: center;margin-left: 30px;">
           <a @click="add_category(record)" style="float: left;margin-left: 10px;font-size: 14px;color: #d29328;">编辑</a>
           <a-menu-item style="margin-left: 10px;float: left;margin-top: 0px;">
            <a-popconfirm title="确定删除该尺寸吗?" @confirm="() => delete_huchi(record.id)">
              <a style="font-size: 14px;color: #d29328;">删除</a>
            </a-popconfirm>
          </a-menu-item>
          </div>
        </span>
      </a-table>
    </div>

    <AddjinBodysizeModule ref="modalForm" @ok="modalFormOk"></AddjinBodysizeModule>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {putAction,getFileAccessHttpUrl} from '@/api/manage';
  import JDate from '@/components/jeecg/JDate.vue'
  import '@/assets/less/TableExpand.less'
  import AddjinBodysizeModule from './modules/AddjinBodysizeModule'
  import { httpAction, postAction, getAction } from '@/api/manage'

  export default {
    name: "categoryinfo",
    mixins:[JeecgListMixin],
    components: {
      JDate,
      AddjinBodysizeModule
    },
    data () {
      return {
        description: 'categoryinfo管理页面',
        tabs: 1,//切换框
        confirmLoading:false,
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'量体尺寸名称',
            align:"center",
            dataIndex: 'bodySizename'
          },
          {
            title:'编号',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'类型',
            align:"center",
            dataIndex: 'isJin',
            customRender(index) {
              if(index=='1'){
                return "净体尺寸"
              }else {
                return "成衣尺寸"
              }
            }
          },
          {
            title:'单位',
            align:"center",
            dataIndex: 'unit'
          },
          {
            title:'排列序号',
            align:"center",
            dataIndex: 'numbers'
          },
          {
            title:'量体最小值',
            align:"center",
            dataIndex: 'min'
          },
          {
            title:'量体最大值',
            align:"center",
            dataIndex: 'max'
          },
          {
            title:'是否必填',
            align:"center",
            dataIndex: 'isBitian',
            customRender(index) {
              if(index=='1'){
                return "必填"
              }else {
                return "非必填"
              }
            }
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/admin/parameter/test_jinti_bodysize?category_id="+this.$route.query.category_id+"&type=1",
          delete_bodysize: "/admin/parameter/delete_bodysize",
          import_bodysizes: "/admin/ImportData/import_bodysizes_Excel",
        }
      }
    },
    methods: {
      /**
       * 导入数据
       */
      importExcel(param){
        this.confirmLoading = true;
        let formData = new FormData()
        formData.append('file', param.file);
        formData.append('category_id', this.$route.query.category_id);
        formData.append('type', 1);
        postAction(this.url.import_bodysizes,formData).then((res)=>{
          console.log(res)
          if(res.code=='0'){
            this.confirmLoading = false;
            this.$message.success(res.msg);
            this.loadData();
          }else {
            this.confirmLoading = false;
            this.$message.error(res.msg);
          }
        });
      },
      /**
       * 导出
       */
      exportExcel(){
        let url = getFileAccessHttpUrl(window._CONFIG['domianURL'] + "/admin/ExportData/export_bodysizes?category_id=" + this.$route.query.category_id+"&type=1")
        window.open(url);
      },
      delete_huchi(id){
        let params = {canshu_id:id};
        httpAction(this.url.delete_bodysize,params,"put").then((res)=>{
          if(res.success){
            this.$message.success(res.message);
            this.loadData();
          }else {
            this.$message.error(res.message);
          }
        });
      },
      add_category(record) {
        this.$refs.modalForm.edit(record);
        if(record=='0'){
          this.$refs.modalForm.title = "新增净体尺寸项";
        }else {
          this.$refs.modalForm.title = "编辑净体尺寸";
        }
        this.$refs.modalForm.disableSubmit = true;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>